#include "switchcross.h"
#include"gamecontrol.h"

SwitchCross::SwitchCross()
{
    this->setPos(470,635);
    this->setPixmap(QPixmap(":/1/Image/StrategyRight.png"));
    onSwitch = false;
}

void SwitchCross::collision()
{
    QRectF mSwitch = QRectF(this->x()+20,this->y()+25,this->boundingRect().width()-30,this->boundingRect().height()-30);

    QRectF mManBlueRect = QRectF(GameControl::Instance()->getManBlue().x()+35,GameControl::Instance()->getManBlue().y()+25,35,50);

    QRectF mManRedRect = QRectF(GameControl::Instance()->getManRed().x()+25,GameControl::Instance()->getManRed().y()+25,40,50);

    if(mSwitch.intersects(mManBlueRect) || mSwitch.intersects(mManRedRect) )
    {
        if(GameControl::Instance()->mKeyList.contains(Qt::Key_A) || GameControl::Instance()->mKeyList.contains(Qt::Key_1))
        {
            this->setPixmap(QPixmap(":/1/Image/StrategyLeft.png"));
            onSwitch = true;
        }
        if(GameControl::Instance()->mKeyList.contains(Qt::Key_D) || GameControl::Instance()->mKeyList.contains(Qt::Key_3))
        {
            this->setPixmap(QPixmap(":/1/Image/StrategyRight.png"));
            onSwitch = false;
        }
    }
}

void SwitchCross::move()
{
    if(GameControl::Instance()->getmStrategyCross().y()!=590 && onSwitch == true )
    {
        GameControl::Instance()->getmStrategyCross().moveBy(0,1);
    }
    else if(GameControl::Instance()->getmStrategyCross().y()!=490 && onSwitch == false )
    {
        GameControl::Instance()->getmStrategyCross().moveBy(0,-1);
    }
}

